<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户注册</title>
    <script data-th-src="@{/layui/layui.js}"></script>
    <link rel="stylesheet" data-th-href="@{/layui/css/layui.css}">
    <style>
        body {
            height: 100vh;
            display: flex;
            align-items: center;
        }
    </style>
</head>
<body>
<div class="layui-container">
    <div class="layui-row">
        <div class="layui-col-sm-offset4 layui-col-md-offset2 layui-col-md4 layui-col-sm3">
            <form data-th-action="@{/register}" method="post" class="layui-form">
                <input type="hidden" name="avatar" value="1">
                <div class="layui-form-item">
                    <label class="layui-form-label">昵称:</label>
                    <div class="layui-input-block">
                        <input type="text" name="nickName" class="layui-input" autocomplete="off" required>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">用户名:</label>
                    <div class="layui-input-block">
                        <input type="text" name="account" class="layui-input" autocomplete="off" required>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">密码:</label>
                    <div class="layui-input-block">
                        <input type="password" name="password" class="layui-input" required>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">邮箱:</label>
                    <div class="layui-input-block">
                        <input type="email" name="email" class="layui-input" required>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">身份证:</label>
                    <div class="layui-input-block">
                        <input type="text" name="identity" class="layui-input" required>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <input class="layui-btn layui-btn-primary" type="submit" lay-submit lay-filter="*" value="注册">
                        <input class="layui-btn " type="reset" value="重置">
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script>
    layui.use(["element","form","layer","jquery"], function () {
        let {form,layer,$}=layui;

        form.on("submit(*)",function(e){
            $.ajax({
                type:'put',
                url:'[(@{/register})]',
                data:e.field,
                dataType:'json',
                success:function(rs){
                    if(rs.code==0){
                        location.href="/login";
                    }else{
                        console.error("注册失败:",rs);
                        layer.msg(rs.msg);
                    }
                }
            })
            return false;
        })
    })
</script>
</body>
</html>